package com.yzyz.service.impl;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.yzyz.bean.book.BookBean;
import com.yzyz.dao.IBookDao;
import com.yzyz.service.IBookService;
import com.yzyz.utils.error.Error;

@Transactional
public class BookServiceImpl implements IBookService {

	private IBookDao bookDao;
	
	@Override
	public int add(Object object) {
		
		return this.bookDao.save(object);
	}

	@Override
	public int delete(int id) {
		BookBean book = (BookBean)this.bookDao.get(id);
		if(book == null) {
			return Error.CAN_NOT_FIND_OBJECT;
		}
		this.bookDao.delete(id);
		return Error.SUCCESS;
	}

	@Override
	public Object find(int id) {
		return this.bookDao.get(id);
	}

	@Override
	public List<?> paginate(int start, int limit) {
		
		return this.bookDao.paginate(start, limit);
	}

	@Override
	public int update(Object object) {
		BookBean book = (BookBean)this.bookDao.get(((BookBean)object).getId());
		if(book == null) {
			return Error.CAN_NOT_FIND_OBJECT;
		}
		this.bookDao.update(object);
		return Error.SUCCESS;
	}

	@Override
	public void setBookDao(IBookDao bookDao) {
		this.bookDao = bookDao;
		
	}

	@Override
	public int getCount() {
		
		return this.bookDao.getCount(-1);
	}

}
